﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Collections.ObjectModel;
using HigLabo.WindowsAzure.RestService.Extensions;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class OperatingSystemFamilies
    {
        public static readonly String ElementName = "OperatingSystemFamilies";

        private Collection<OperatingSystemFamily> _OperatingSystemFamily = new Collection<OperatingSystemFamily>();
        public IEnumerable<OperatingSystemFamily> OperatingSystemFamilyList
        {
            get { foreach (var item in _OperatingSystemFamily) { yield return item; } }
        }

        public OperatingSystemFamilies(XElement xml)
        {
            IEnumerable<XElement> els;
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            /*OperatingSystemFamilies*/
            els = xml.ElementsByLocalName(OperatingSystemFamily.ElementName);
            foreach (var item in els)
            {
                var add = new OperatingSystemFamily(item);
                this._OperatingSystemFamily.Add(add);
            }
        }
    }

    public class OperatingSystemFamily
    {
        public static readonly String ElementName = "OperatingSystemFamily";

        public String Name { get; private set; }
        public String Label { get; private set; }
        public OperatingSystems OperatingSystemList { get; private set; }

        public OperatingSystemFamily(XElement xml)
        {
            XElement el;
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            /*OperatingSystemFamily*/
            this.Name = xml.ValueOrEmpty("Name");
            this.Label = Base64Converter.From(xml.ValueOrEmpty("Label"));
            el = xml.ElementByLocalName(OperatingSystems.ElementName);
            if (el != null)
            {
                this.OperatingSystemList = new OperatingSystems(el);
            }
        }
    }
}
